<template>
  <div class="reactive-layout-item-form">
    <Form :label-width="105">
      <FormItem label="ID">
        <Input size="small" v-model="id" disabled/>
      </FormItem>

      <FormItem label="背景颜色">
        <ColorPicker size="small" v-model="backgroundColor" alpha/>
      </FormItem>

      <FormItem label="边框宽度">
        <InputNumber size="small" :max="10000" :min="0" :step="1" v-model="borderWidth"></InputNumber> px
      </FormItem>
      <FormItem label="边框类型">
        <Select size="small" v-model="borderStyle">
          <Option v-for="item in $PnDict.borderStyles" :value="item.value" :key="item.value">{{ item.label }}</Option>
        </Select>
      </FormItem>
      <FormItem label="边框颜色">
        <ColorPicker size="small" v-model="borderColor" alpha/>
      </FormItem>

      <FormItemPanel title="边框圆角">
        <FormItem label="上左">
          <InputNumber size="small" :max="10000" :min="0" :step="1" v-model="borderTopLeftRadius"></InputNumber> px
        </FormItem>
        <FormItem label="上右">
          <InputNumber size="small" :max="10000" :min="0" :step="1" v-model="borderTopRightRadius"></InputNumber> px
        </FormItem>
        <FormItem label="下右">
          <InputNumber size="small" :max="10000" :min="0" :step="1" v-model="borderBottomLeftRadius"></InputNumber> px
        </FormItem>
        <FormItem label="下左">
          <InputNumber size="small" :max="10000" :min="0" :step="1" v-model="borderBottomRightRadius"></InputNumber> px
        </FormItem>
      </FormItemPanel>


      <FormItem label="内边距">
        <InputNumber size="small" :max="10000" :min="0" :step="1" v-model="padding"></InputNumber> px
      </FormItem>
      <FormItem label="是否显示">
        <Select :transfer="true" size="small" v-model="display">
          <Option v-for="item in $PnDict.display" :value="item.value" :key="item.value">{{ item.label }}</Option>
        </Select>
      </FormItem>
      <FormItem label="关联组件">
        <Input size="small" v-model="componentName" disabled/>
      </FormItem>
    </Form>
  </div>
</template>

<script>
  import { createHelpers } from 'vuex-map-fields';

  const { mapFields } = createHelpers({
    getterType: 'designer/getLayoutItem',
    mutationType: 'designer/updateLayoutItem',
  });

  export default {
    name: 'ReactiveLayoutItemForm',
    data() {
      return {}
    },
    mounted() {

    },
    methods: {


      /**
       * 弃用
       */
      selectFuncComp () {

        this.componentId = this.$PnUtil.uuid();
        this.componentName = 'Hello';

        const componentsContext = require.context('../../', true, /\.vue$/);

        componentsContext.keys().forEach(fileName => {
          const componentConfig = componentsContext(fileName);

          if(componentConfig.default.name == 'Hello') {
            const compInst = require('../../'+fileName.slice(2, fileName.length));
            this.componentConfigData = Object.assign({}, compInst.default.attr.configDataTemp)
          }
        });

      }
    },
    computed: {
      ...mapFields({
        id: 'id',

        borderWidth: 'layoutItemConfigData.borderWidth',
        borderStyle: 'layoutItemConfigData.borderStyle',
        borderColor: 'layoutItemConfigData.borderColor',

        borderTopLeftRadius: 'layoutItemConfigData.borderTopLeftRadius',
        borderTopRightRadius: 'layoutItemConfigData.borderTopRightRadius',
        borderBottomLeftRadius: 'layoutItemConfigData.borderBottomLeftRadius',
        borderBottomRightRadius: 'layoutItemConfigData.borderBottomRightRadius',

        backgroundColor: 'layoutItemConfigData.backgroundColor',
        padding: 'layoutItemConfigData.padding',

        display: 'layoutItemConfigData.display',

        componentId: 'component.id',
        componentName: 'component.name',
        componentConfigData: 'component.compConfigData'
      })
    }
  }
</script>

<style scoped>
  .ivu-form-item {
    margin-bottom: 0px;
  }
</style>
